package com.aurora.gulimall.product.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author Aurora
 * createTime 2023.01.08 15:50:34
 * @className MyMybatisConfiguration.java
 */
@Configuration
@EnableTransactionManagement//开启事务
@MapperScan("com.aurora.gulimall.product.dao")
public class MyMybatisConfiguration {
//    @Bean
//    public PaginationInnerInterceptor paginationInnerInterceptor(){
//        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
//        paginationInnerInterceptor.setOverflow(true);//设置请求页面大于最大页后操作，true回到首页，false继续请求 默认false
//        paginationInnerInterceptor.setMaxLimit(1000l);//设置单页限制条数 默认500  -1表示不受限制
//        return paginationInnerInterceptor;
//    }

    @Bean
    public MybatisPlusInterceptor paginationInterceptor(){
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        paginationInnerInterceptor.setOverflow(true);//设置请求页面大于最大页后操作，true回到首页，false继续请求 默认false
        paginationInnerInterceptor.setMaxLimit(1000l);//设置单页限制条数 默认500  -1表示不受限制
        mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor);
        return mybatisPlusInterceptor;
    }
}
